﻿using Micro.Extensions.Utilities;
using Micro.Srv.LogCenter.Services.Interfaces;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System;
using System.Threading.Tasks;

namespace Micro.Srv.LogCenter.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class ChainLogController : ControllerBase
    {

        private readonly IChainLogService _chainLogService;

        public ChainLogController(IChainLogService chainLogService)
        {
            _chainLogService = chainLogService;
        }

        [HttpGet("GetChainLogByChainId")]
        public async Task<ComResult<ChainLogViewModel[]>> GetChainLogByChainId(string chainId, string logType, LogLevel? logLevel, DateTime? beginTime, DateTime? endTime)
        {
            if (beginTime == null) beginTime = DateTime.Now;
            if (endTime == null) endTime = DateTime.Now;

            return await _chainLogService.GetChainLogsByChainId(chainId, logType, logLevel, beginTime.Value, endTime.Value);
        }
    }

    public class TreeData
    {
        public int Id { get; set; }

        public DateTime Date { get; set; }

        public string Name { get; set; }

        public string Address { get; set; }

        public TreeData[] Children { get; set; }
    }
}